<!doctype HTML>
<html>
<meta charset="utf8">
<title>Content Visibility: accessibility press</title>
<link rel="author" title="Rakina Zata Amni" href="mailto:rakina@chromium.org">
<link rel="help" href="https://github.com/WICG/display-locking">
<meta name="assert" content="content-visibility auto subtrees are exposed by accessibility press">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div style="height:10000px;">
  spacer so that everything below will be offscreen (and won't get viewport-activated)
</div>
<div id="hidden" style="content-visibility: auto">
  foo
  <div id="child" tabindex="0">
    bar
  </div>
</div>

<script>
function axElementById(id) {
  return accessibilityController.accessibleElementById(id);
}

// #hidden is locked, and thus is saved as an AXNodeObject instead of an AXLayoutObject,
// and has 3 child nodes: "foo" text, "<newline>" text, and #child node.
// Note that we have the separate <newline> text because it's an AXNodeObject and does
// not do whitespace collapsing (though this might change in the future).
async_test((t) => {
  let axHidden = axElementById("hidden");
  t.step(() => { assert_equals(axHidden.childrenCount, 3, "Children count when locked"); });

  // Press on the #child. This will cause the element to be brought into the view,
  // since it is interactable even though it is locked by content-visibility (see
  // https://github.com/WICG/display-locking for details). When that is done,
  // the element will become unlocked and AXNodeObjects will be replaced with
  // AXLayoutObjects. Still, the <newline> that already existed will be around, but
  // marked as ignored.
  axElementById("child").press();
  // Wait for the next frame for the ax object to be recreated.
  requestAnimationFrame(() => {
    requestAnimationFrame(() => {
      axHidden = axElementById("hidden");
      // #hidden is now unlocked and saved as a normal AXLayoutObject, but it still has the same
      // three child nodes. The whitespace node is still present because it was already created,
      // but it's marked as ignored
      t.step(() => { assert_equals(axHidden.childrenCount, 3, "Children count after activation"); });
      const axChild = axHidden.childAtIndex(2);
      t.step(() => { assert_true(axChild.isIgnored, "After update, isIgnored is true on whitespace node"); });
      t.done();
    });
  });
}, "Accessiblility press() causes activatable hidden tree to activate");

</script>
